<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>P82 【例4-6】demo06.html</title>
</head>

<body>
    <script>
        function factorial(n) {
            if (n == 1) {
                return 1;
            }
            return n * factorial(n - 1);
        }
        var n = promt('求n的阶乘\n n是大于等于1的正整数，如2表示求2！。');
        n = parseInt(n);
        if (isNaN(n)) {
            console.log('输入的n值不合法');
        } else {
            console.log(n + '的阶乘为：' + factorial(n));
        }
    </script>
    <a href="../首页/page04.html">
        <h2>返回上一页面</h2>
    </a>
</body>

</html>